<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/home/config.php';

$array_return = array();
$array_return['status'] = 0;
$array_return['html'] = '';

$page = getValue('page','int','POST',2);
$start = ($page - 1)*20;
$query = getValue('query','str','POST','');
$query = json_decode(base64_decode($query),1);
//$query = $query[0];
//$array_return['html'] = $query;
//die(json_encode($array_return));

$list_services = db_array('SELECT * 
                           FROM services
                           WHERE ser_active = 1'.$query.'
                           LIMIT '.$start.',20');
$total_products = count($list_services);
$arr_os = array('android'=>'Android','ios'=>'IOS (iPhone)','windows'=>'Windows Phone','other'=>'HĐH khác');
$list_instock_status = array(0=>'Hết hàng',1=>'Còn hàng',2=>'Sắp về',3=>'Sắp ra mắt');
if($total_products == 0) {
   $array_return['html'] = 'Hết sản phẩm';
}elseif($total_products > 0 && $total_products < 20) {
   foreach($list_services as $service) {
      $array_return['status'] = 2;
      $array_return['html'] .= '<div class="proitem">
                     <a href="'.url_services_detail($service).'">
                        <img src="'.img_link($service['ser_image'],'small').'" alt="'.$service['ser_name'].'" />
                        <h3 class="name">'.$service['ser_name'].'</h3>
                        <p class="price">Bảo hành: '.$service['ser_warranty'].'</p>
                     </a>
                  </div>';
   }
}else {
   foreach($list_services as $service) {
      $array_return['status'] = 1;
      $array_return['html'] .= '<div class="proitem">
                     <a href="'.url_services_detail($service).'">
                        <img src="'.img_link($service['ser_image'],'small').'" alt="'.$service['ser_name'].'" />
                        <h3 class="name">'.$service['ser_name'].'</h3>
                        <p class="price">Bảo hành: '.$service['ser_warranty'].'</p>
                     </a>
                  </div>';
   }
}

die(json_encode($array_return));
?>